#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string clearStars(string s) {
        vector<vector<int>> stacks(26);
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] != '*')
            {
                stacks[s[i] - 'a'].push_back(i);
                continue;
            }
            for (auto& stk : stacks)
            {
                if (stk.size())
                {
                    stk.pop_back();
                    break;
                }
            }
        }

        vector<int> index;
        for (auto& stk : stacks)
        {
            index.insert(index.end(), stk.begin(), stk.end());
        }
        sort(index.begin(), index.end());
        string res;
        for (auto& e : index) res += s[e];
        return res;
    }
};